local skill = fk.CreateSkill{
  name = "tea__qiaozhu&"
}
---@type ActiveSkillSpec
local qiaozhu_active = {
  anim_type = "support",
  target_num = 0,
  card_num = 1,
  prompt = "#tea__qiaozhu&-invoke",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:hasSkill(self)
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = table.filter(room:getOtherPlayers(player), function(p)
      return p:hasSkill("tea__qiaozhu") and not p.dead
    end)[1]
    room:obtainCard(target, effect.cards, true, fk.ReasonGive, player.id)
    if not target.dead then
      room:setPlayerMark(target, "tea__qiaozhu-block-phase", 1)
      player:showCards(effect.cards)
      local ctype = Fk:getCardById(effect.cards[1]):getTypeString()
      local cards = room:askToCards(player, {
        skill_name = self.name,
        min_num = 1,
        max_num = 999,
        include_equip = true,
        cancelable = true,
        pattern = ".|.|.|.|.|^"..ctype,
        prompt = "#qiaozhu_recast:::"..ctype,
      })
      if #cards > 0 then
        room:recastCard(cards, target, self.name)
        local givenCards = room:askToCards(player, {
          skill_name = self.name,
          min_num = 1,
          max_num = 999,
          include_equip = true,
          cancelable = true,
          pattern = ".|.|.|.|.|^"..ctype,
          prompt = "#qiaozhu_give:"..player.id.."::"..ctype,
        })
        if #givenCards > 0 then
          room:obtainCard(player, givenCards, false, fk.ReasonGive)
        end
      end
      room:setPlayerMark(target, "tea__qiaozhu-block-phase", 0)
    end
  end,
}
skill:addEffect("active", qiaozhu_active)

return skill